package cn.edu.yzu.scholarship.validator;

import cn.edu.yzu.scholarship.kit.Sak;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.validate.Validator;

public class ChangeAdminPwdValidator extends Validator {

	@Override
	protected void validate(Controller c) {
		this.validateRequired("oldPwd", "errorInfo", "请输入原密码！");
		this.validateRequired("newPwd", "errorInfo", "请输入新密码！");
		this.validateRequired("confirmPwd", "errorInfo", "请确认新密码！");
		this.validateEqualString(c.getPara("oldPwd"), ((Record)c.getSessionAttr("user")).getStr("managePwd"), "errorInfo", "输入的密码不正确，请重新输入！");
		this.validateEqualField("newPwd", "confirmPwd", "errorInfo", "两次输入密码信息不一致！");
	}

	@Override
	protected void handleError(Controller c) {
		c.renderText(Sak.toJsonStr("errorInfo",c.getAttr("errorInfo")));
		//c.renderJson("errorInfo",c.getAttr("errorInfo"));//IE BUG
	}

}
